# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=cargo-local-registry
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.3
pkgrel=1
pkgdesc="A cargo subcommand to manage local registries (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/dhovart/cargo-local-registry"
license=('MIT' 'Apache')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
options=('staticlibs' 'strip')
source=("$_realname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz")
sha256sums=('5182f49a99d0a9cc6f821b3471a3f9efe74f3a64ae1853db7d1e597dd4f0100e')

prepare() {
  cd "${srcdir}"
  rm -rf "build-${MSYSTEM}" | true
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" fetch
}

build() {
  msg "Cargo build for ${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" build \
    --release \
    --locked
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" test \
    --release \
    --locked
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 "README.md" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/README.md"
  install -Dm644 "LICENSE-MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
  install -Dm644 "LICENSE-APACHE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-APACHE"
}

